<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <div v-if="meta.indexOf('ComboTransfer') > -1" class="doumee_table_header">
      <el-button
        v-preventReClick
        type="primary"
        @click="handleTransfer"
      >{{ $t('message.tczr') }}</el-button>
    </div>
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
    >
      <el-table-column
        align="center"
        :label="$t('message.zrtc')"
        prop="transName"
        min-width="250"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.zchy')"
        prop="outMemberCard"
        min-width="260"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.zrhy')"
        prop="inMemberCard"
        min-width="260"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.zrsm')"
        prop="info"
        min-width="140"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.czr')"
        prop="creatorName"
        min-width="100"
        fixed="right"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.zrsj')"
        prop="createTime"
        min-width="160"
        fixed="right"
        show-overflow-tooltip
      />
    </el-table>
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
    <Transfer
      v-if="isShowTransfer"
      ref="TransferRef"
      @success="TransferSuccess"
      @close="isShowTransfer = false"
    />
  </div>
</template>

<script>
import { transferMealsList } from '@/api'
import { parseTime } from '@/utils/index'
import QueryForm from '@/components/QueryForm'
import Transfer from '../comboTransfer'
export default {
  name: 'ComboTransferHistory',
  components: {
    QueryForm,
    Transfer
  },
  data() {
    return {
      isShowTransfer: false,
      list: [],
      meta: [],
      totalCount: 0,
      queryFormConfig: {
        formItems: [{
          filed: 'transferOut',
          type: 'input',
          label: this.$t('message.zchy'),
          placeholder: this.$t('message.hy2'),
          clearable: true
        }, {
          filed: 'transferIn',
          type: 'input',
          label: this.$t('message.zrhy'),
          placeholder: this.$t('message.hy2'),
          clearable: true
        }],
        online: true
      },
      pagination: {
        page: 1,
        rows: 10
      },
      listLoading: true,
      filters: {}
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    // this.meta = ['ComboTransfer']
    this.getList(1)
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    handleTransfer() {
      this.isShowTransfer = true
      this.$nextTick(() => {
        this.$refs.TransferRef.isShow = true
      })
    },
    TransferSuccess() {
      this.isShowTransfer = false
      this.getList()
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取列表
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      filters.flag = '1'
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      transferMealsList({ pagination, param: { venueId, ...filters }, userId: sessionStorage.getItem('userId') })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.totalCount = res.totalCount
          this.list = res.recordList
          if (res.totalCount && res.recordList.length === 0 && pagination.page > 1) {
            this.getList(Math.ceil(res.totalCount / pagination.rows))
          }
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    // 清空
    clear() {
      this.filters = {}
      this.getList(1)
    }

  }
}
</script>
